package edu.mse.camel.client.chat.actions;

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IViewActionDelegate;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPart;

public class SaveFileActionDelegate implements IObjectActionDelegate,
IViewActionDelegate{

	@Override
	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void init(IViewPart view) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void run(IAction action) {
		FileDialog fd = new FileDialog(new Shell(), SWT.SAVE);
		fd.setText("Save as");
		String[] filterExt = {"*.txt"};
		fd.setFilterExtensions(filterExt);
		//fd.setOverwrite(true);
		String filename = fd.open();
		if(!filename.equals("")){
			SaveChat saveToFile = new SaveChat();
			saveToFile.save(filename);
		}
	}

	@Override
	public void selectionChanged(IAction action, ISelection selection) {
		
	}	
}
